package com.bbm.bbmanage.controller;

import com.bbm.bbmanage.entity.Comment;
import com.bbm.bbmanage.entity.vo.ResponseResult;
import com.bbm.bbmanage.service.CommentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Comment)表控制层
 *
 * @author lionkliu
 * @since 2023-12-07 14:30:00
 */
@RestController
@RequestMapping("comment")
public class CommentController {

    @Resource
    private CommentService commentService;

    @GetMapping("{id}")
    public ResponseResult getCommentByHouseId(@PathVariable Long id) {
        return commentService.getCommentByHouseId(id);
    }

    @GetMapping("/finish/{userId}")
    public ResponseResult getFinishedComment(@PathVariable Long userId) {
        return commentService.getFinishedComment(userId);
    }


    @GetMapping("/page")
    public ResponseResult selectPage(@RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize) {
        return commentService.selectPage(pageNum, pageSize);
    }

    @GetMapping("/search")
    public ResponseResult search(@RequestParam(value = "userId", required = false) Integer userId,
                                 @RequestParam(value = "houseId", required = false) Integer houseId,
                                 @RequestParam(value = "content", required = false) String content,
                                 @RequestParam("pageNum") Integer pageNum,
                                 @RequestParam("pageSize") Integer pageSize) {
        return commentService.search(pageNum, pageSize, userId, houseId, content);
    }

    @PostMapping
    public ResponseResult insert(@RequestBody Comment comment) {
        return commentService.insertOne(comment);
    }

    @PutMapping
    public ResponseResult update(@RequestBody Comment comment) {
        return commentService.updateOne(comment);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        return commentService.deleteById(id);
    }

}
